package com.smile.ye.http;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.smile.ye.data.dto.CartOrderQueryDto;
import com.smile.ye.data.entity.CartDetailEntity;
import com.smile.ye.response.Result;
import com.smile.ye.service.CartOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/carts")
@Api(tags = "购物车")
public class CartOrderController {
    @Autowired
    CartOrderService service;

    @ApiOperation("分页查询")
    @GetMapping
   private Result query(CartOrderQueryDto dto){
        return service.query(dto);
    }

    @ApiOperation("根据购物车详情")
    @GetMapping("/{id}")
    private Result queryById(@PathVariable String id){
        return  service.queryById(id);
    }

    @ApiOperation("创建购物车")
    @PostMapping
    private Result create(@RequestBody CartDetailEntity item) throws JsonProcessingException {
      return service.create(item);
    }

    @ApiOperation("刷新购物车")
    @PutMapping("/{cart}")
    private Result refresh(@PathVariable String cart, @RequestBody CartDetailEntity item) throws JsonProcessingException {
        return service.refresh(cart,item);
    }

    @ApiOperation("清空购物车")
    @PutMapping("/{cart}/clear")
    private Result clear(@PathVariable String cart) throws JsonProcessingException {
        return service.clear(cart);
    }

//    @ApiOperation("刷新状态")
//    @PutMapping("/{cart}/status")
//    private Result clear(@PathVariable String cart,@Re){
//        return service.clear(cart);
//    }


    @ApiOperation("删除购物车")
    @DeleteMapping("/{id}")
    private Result remove(@PathVariable String id){
        return  service.remove(id);
    }
}
